<template>
  <div class="container">
    <h1>{{ title }}</h1>

    <div class="content">
      <div class="first-group group">
        <div
          class="first-item item"
          :class="{'actived': judgeActived(item), 'lock': item.lock}"
          v-for="item of mutexList.filter(i => i.category === 'first')"
          :key="item.id"
          @click="handleClick(item)"
        >{{ item.name }}</div>
      </div>
      <div class="second-group group">
        <div
          class="second-item item"
          :class="{'actived': judgeActived(item), 'lock': item.lock}"
          v-for="item of mutexList.filter(i => i.category === 'second')"
          :key="item.id"
          @click="handleClick(item)"
        >{{ item.name }}</div>
      </div>
      <div class="third-group group">
        <div
          class="third-item item"
          :class="{'actived': judgeActived(item), 'lock': item.lock}"
          v-for="item of mutexList.filter(i => i.category === 'third')"
          :key="item.id"
          @click="handleClick(item)"
        >{{ item.name }}</div>
      </div>

      <div class="res-list">
        <div class="res-title">选择结果</div>
        <div class="res-item" v-for="item of selectedList" :key="item.id">{{item.name}}</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import {MockData} from './mock';
import { useMutex } from './composition/index'
import { TabItem } from './types';

const {mutexList, selectedList, handleSelect, judgeActived } = useMutex(MockData)

const title = ref<string>('MutexPage');

const handleClick = (item: TabItem) => {
  const [res, status] = handleSelect(item) // 返回结果：[是否可以操作（非置灰）, 是否处于激活]
  if(res) {
    console.log(`你${status ? '选择了' : '放弃了'}${item.name}`)
    console.log('selectedList', selectedList.value)
  }
}

</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  font-size: 26px;
  padding-top: 40px;
  .content {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 10px 16px;
    .group {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      margin-top: 40px;
      width: 250px;
      .item {
        width: 70px;
        height: 34px;
        border: 2px solid rgb(109, 109, 109);
        border-radius: 10px;
        line-height: 34px;
        text-align: center;
      }

      .actived {
        border: 2px solid rgb(240, 77, 27);
      }
      .lock{
        background-color: rgb(146, 146, 146);
      }
    }
    .first-group {
    }
    .second-group {
    }
    .third-group {
    }

    .res-list {
      margin-top: 40px;
      width: 100%;
      .res-title{
        font-size: 30px;
      }
      .res-item{
        margin-top: 10px;
        border: 1px solid rgb(151, 150, 150);
      }
    }
  }
}
</style>